﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace OpenComposite.Workflow
{
	#region Class: CompensationGlyph : Base: DesignerGlyph
	public class CompensationGlyph : DesignerGlyph
	{
		public CompensationGlyph(EventHandler action)
		{
			_handleClick = action;
		}

		public override bool CanBeActivated
		{
			get
			{
				return true;
			}
		}

		private EventHandler _handleClick;

		protected override void OnActivate(ActivityDesigner designer)
		{
			_handleClick(this, EventArgs.Empty);
			base.OnActivate(designer);
		}

		public override Rectangle GetBounds(ActivityDesigner designer, bool activated)
		{
			Rectangle imageBounds = new Rectangle();
			Size glyphSize = WorkflowTheme.CurrentTheme.AmbientTheme.GlyphSize;
			imageBounds.Location =
				new Point(designer.Bounds.Right - glyphSize.Width / 2 - glyphSize.Width - 3,
					designer.Bounds.Top - glyphSize.Height / 2);
			imageBounds.Size = glyphSize;
			return imageBounds;
			//return base.GetBounds(designer, activated);
		}

		protected override void OnPaint(Graphics graphics, bool activated, AmbientTheme ambientTheme, ActivityDesigner designer)
		{
			Rectangle bounds = GetBounds(designer, activated);

			graphics.FillEllipse(Brushes.White, bounds);
			graphics.DrawEllipse(ambientTheme.ForegroundPen, bounds);
			bounds.Inflate(-2, -2);
			Point center = WorkflowHelpers.GetCenter(bounds);
			graphics.FillPolygon(Brushes.Black,
				new Point[]{
					new Point(bounds.Left, center.Y),
					new Point(center.X, bounds.Top),
					new Point(center.X, bounds.Bottom)
				});
			graphics.FillPolygon(Brushes.Black,
				new Point[]{
					new Point(center.X, center.Y),
					new Point(bounds.Right, bounds.Top),
					new Point(bounds.Right, bounds.Bottom)
				});

		}
	}
	#endregion

	#region Class: ExceptionGlyph : Base: DesignerGlyph
	public class ExceptionGlyph : DesignerGlyph
	{
		public ExceptionGlyph(EventHandler action)
		{
			_handleClick = action;
		}

		public override bool CanBeActivated
		{
			get
			{
				return true;
			}
		}

		private EventHandler _handleClick;

		protected override void OnActivate(ActivityDesigner designer)
		{
			_handleClick(this, EventArgs.Empty);
			base.OnActivate(designer);
		}

		public override Rectangle GetBounds(ActivityDesigner designer, bool activated)
		{
			Rectangle imageBounds = new Rectangle();
			Size glyphSize = WorkflowTheme.CurrentTheme.AmbientTheme.GlyphSize;
			imageBounds.Location = new Point(designer.Bounds.Right - glyphSize.Width / 2, designer.Bounds.Top - glyphSize.Height / 2);
			imageBounds.Size = glyphSize;
			return imageBounds;
			//return base.GetBounds(designer, activated);
		}

		protected override void OnPaint(Graphics graphics, bool activated, AmbientTheme ambientTheme, ActivityDesigner designer)
		{
			Rectangle bounds = GetBounds(designer, activated);
			graphics.FillEllipse(Brushes.White, bounds);
			graphics.DrawEllipse(ambientTheme.ForegroundPen, bounds);

			bounds.Inflate(-5, -2);
			GraphicsPath path = new GraphicsPath();
			path.AddLine(bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
			path.AddLine(bounds.Left, bounds.Bottom, bounds.Left + 1, bounds.Top - 1);
			path.CloseFigure();
			path.AddLine(bounds.Right, bounds.Bottom, bounds.Right, bounds.Top);
			path.AddLine(bounds.Right, bounds.Top, bounds.Right - 1, bounds.Bottom + 1);
			path.CloseFigure();
			path.AddLine(bounds.Right - 1, bounds.Bottom, bounds.Left + 1, bounds.Top);
			using ( Pen p = new Pen(Brushes.Black) ) {
				graphics.DrawPath(p, path);
			}
			//graphics.FillPath(theme.ForegroundBrush, path);

		}
	}
	#endregion

}
